#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Sun May 26 09:36:45 2013

@author: Sat Kumar Tomer
@email: satkumartomer@gmail.com
@website: www.ambhas.com
"""

import numpy as np
from ambhas.interpolation import thiessen_polygon
import matplotlib.pyplot as plt
import os

# outfile paths
image_location_gauge = '../images/rain_location_gauge.png'
image_thiessen_rain = '../images/rain_thiessen_rain.png'

# convert relative path into absolute 
cur_dir = os.path.dirname(__file__)
image_location_gauge = os.path.join(cur_dir, image_location_gauge)
image_thiessen_rain = os.path.join(cur_dir, image_thiessen_rain)

# generate some synthetic data
x = np.random.random(5) 
y = np.random.random(5)
X = np.linspace(0, 1, 200)
Y = np.linspace(0, 1, 200)
rain = np.random.random(5)

# plot the location of gauges
plt.clf()
plt.plot(x,y,'ro')
plt.xlim((X.min(),X.max()))
plt.ylim((Y.min(),Y.max()))
plt.xlabel('X')
plt.ylabel('Y')
plt.savefig(image_location_gauge)
plt.close()

# interpolate using thiessen polygon
data = thiessen_polygon(x, y, rain, X, Y)

# plot the interpolated data
plt.clf()
plt.pcolor(X,Y,data, vmin=0, vmax=1)
plt.plot(x,y,'*')
plt.xlabel('X')
plt.ylabel('Y')
plt.colorbar()
plt.savefig(image_thiessen_rain)
plt.close()


